package tree.leetcode_114_medium;

public class Flatten {
    public void flatten(TreeNode root){
        //递归出口
        if(root == null){
            return;
        }
        //将左树变为链表
        flatten(root.left);
        //将右树变为链表
        flatten(root.right);

        //将左树放到根的右边
        TreeNode temp = root.right;
        root.right = root.left;

        //要将左树置空
        root.left = null;

        //找到树的最右边 把右树形成的链表连接上
        while(root.right != null){
            root = root.right;
        }
        root.right = temp;
    }
}
